window.onload = function () {
  if (typeof QWebChannel !== 'function' || typeof qt === 'undefined') {
    return;
  }
  // 创建 QWebChannel 实例
  const qChannel = new QWebChannel(qt.webChannelTransport, function (channel) {
    // 获取在 Qt 端注册的后端对象
    const backend = channel.objects.backend;
    // 调用 Qt 端的回调函数
    backend.receiveCallback('Button clicked from web page!');
    window.__qChannel = {
      channel: qChannel,
      postMessage: (msg) => {
        console.log("post message to QT: ", msg);
        backend.receiveCallback(JSON.stringify(msg));
      }
    };
  });
};
